<?php

class Seguranca {

	private $hash;
	private $salt;
	private $md5;

	public function __construct( $valor, $md5 = 0, $salt = "a!@123Q)") {

		$this->md5 = $md5;
		$this->salt = $salt;

		if ( $this->md5 == 0 )
			return $this->hash = $valor;
		if ( $this->md5 == 1 ) 
			$this->hash = md5( $valor ); 
		if ( $this->salt )
			$this->hash = md5( $this->hash . $this->salt );

	}

	private function antiInjection( $val ) {
		$val = addslashes( $val );
		return mysql_real_escape_string( $val );
	}

	private function denyChars( $val ) {

		$deny = array('\'', '"', '(', ')', '=');
		$val = str_replace( $deny , "", $val );
		return $val;

	}

	public function getValor( $level = 3 )
	{

		//Transforma o número em binário
		$bin = decbin( $level );

		if ( $bin[1] ) $this->hash = $this->denyChars( $this->hash );
		if ( $bin[0] ) $this->hash = $this->antiInjection( $this->hash );

		return $this->hash;

	}

}

?>